package com.hrm.domain.system;

import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Getter;
import lombok.Setter;

import javax.persistence.*;
import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

/**
 * @Author: 林海湾Sea
 * @Date :  2021/11/26 10:18
 * @Decription: 角色实体类
 */
@Entity
@Table(name = "pe_role")
@Getter
@Setter
public class Role implements Serializable {

    private static final long serialVersionUID = 594829320797158219L;

    @Id
    private String id;
    /**
     * 角色名
     */
    private String name;
    /**
     * 说明
     */
    private String description;
    /**
     * 企业id
     */
    private String companyId;


    /**
     * 角色与用户： 多对多的关系
     */
    @JsonIgnore
    @ManyToMany(mappedBy = "roles")
    private Set<User> users = new HashSet<>(0);


    /**
     * 角色与权限：多对多的关系
     */
    @JsonIgnore
    @ManyToMany
    @JoinTable(name = "pe_role_permission",
            joinColumns = {@JoinColumn(name = "role_id", referencedColumnName = "id")},
            inverseJoinColumns = {@JoinColumn(name = "permission_id", referencedColumnName = "id")})

    // 角色与权限，多对多的关系
    private Set<Permission> permissions = new HashSet<>(0);
}
